<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use apps\category\models\Type;
use apps\category\models\Category;

/**
 * @var yii\web\View $this
 * @var apps\category\models\Category $model
 * @var yii\widgets\ActiveForm $form
 */
?>

<div class="category-form">

    <?php
    $form = ActiveForm::begin([
                'options' => ['enctype' => 'multipart/form-data']]);
    ?>

    <?= $form->field($model, 'type_id')->dropDownList(ArrayHelper::map(Type::find()->all(), 'id', 'name'), ['prompt' => '请选择']) ?>

    <?= $form->field($model, 'parent_id')->dropDownList(['0' => '无'] + ArrayHelper::map(Category::find()->all(), 'id', 'name')) ?>

    <?= $form->field($model, 'code')->textInput(['maxlength' => 20]) ?>

    <?= $form->field($model, 'name')->textInput(['maxlength' => 20]) ?>

    <?= $form->field($model, 'status')->dropDownList(Category::allStatus(), ['prompt' => '请选择']) ?>

    <?= $form->field($model, 'position')->dropDownList(array_combine(range(-50, 50), range(-50, 50)), ['prompt' => '请选择']) ?>

    <?= $form->field($model, 'image_url')->fileInput() ?>

    <?= $form->field($model, 'description')->textarea() ?>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? '新增' : '修改', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
